package zf.display
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * Flash IDE 中Sprite形式的轻量级组件基类
	 * @author Feng.Zhang
	 * 
	 */
	public class FlashSpriteComponent extends Sprite
	{
		protected var isAdd:Boolean=false;
		/**
		 * Flash IDE 中Sprite形式的轻量级组件基类 
		 * 可复制其中代码，但在flash中元件必须继承自Sprite
		 * 
		 */
		public function FlashSpriteComponent()
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE,onAddStageHander);
			this.addEventListener(Event.REMOVED_FROM_STAGE,onRemoveStageHander);
		}
		
		/**
		 * 加载到主场景时执行 
		 * 
		 */
		protected function addStage():void
		{
			
		}
		
		/**
		 * 从主场景删除时执行 
		 * 
		 */
		protected function removeStage():void
		{
			
		}
		
		private function onAddStageHander(e:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE,onAddStageHander);
			isAdd=true;
			addStage();
		}
		
		private function onRemoveStageHander(e:Event):void
		{
			this.removeEventListener(Event.REMOVED_FROM_STAGE,onRemoveStageHander);
			removeStage();
		}
	}
}
